package l2ft.gameserver.ai.FakePcs;

import l2ft.commons.util.Rnd;
import l2ft.gameserver.ai.MainFakePc;
import l2ft.gameserver.model.Creature;
import l2ft.gameserver.model.Skill;
import l2ft.gameserver.model.instances.NpcInstance;
import l2ft.gameserver.tables.SkillTable;

public class MageFakePc extends MainFakePc
{
	private Skill _surrender;
	private Skill _firstVortex;
	private Skill _secondVortex;
	private Skill _firstMainSkill;
	private Skill _secondMainSkill;
	
	public MageFakePc(NpcInstance actor)
	{
		super(actor);
	}
	
	@Override
	protected boolean thinkActive()
	{
		return super.thinkActive() || defaultThinkBuff(10);
	}

	@Override
	protected boolean createNewTask()
	{
		return defaultFightTask();
	}

	@Override
	protected boolean defaultFightTask() 
	{
		Creature target;
		if((target = prepareTarget()) == null)
			return false;
		double distance = getActor().getDistance(target);
		
		//First check for enlightenment
		Skill enlightenment = SkillTable.getInstance().getInfo(1532, 1);
		if(canUseSkill(enlightenment, target) && Rnd.chance(60))
			return chooseTaskAndTargets(enlightenment, getActor(), distance);
		
		//check if skills are set
		getSkills();
		
		//check surrender
		if(!target.isRaid() && canUseSkill(_surrender , target) && target.getEffectList().getEffectsBySkillId(_surrender.getId()) == null)
			return chooseTaskAndTargets(_surrender, target, distance);
		//other skills
		if(canUseSkill(_firstVortex , target))
			return chooseTaskAndTargets(_firstVortex, target, distance);
		if(_secondVortex != null && canUseSkill(_secondVortex , target))
			return chooseTaskAndTargets(_secondVortex, target, distance);
		if(canUseSkill(_firstMainSkill, target))
			return chooseTaskAndTargets(_firstMainSkill, target, distance);
		if(_secondMainSkill != null && canUseSkill(_secondMainSkill, target))
			return chooseTaskAndTargets(_secondMainSkill, target, distance);
		return false;
	}
	
	private void getSkills()
	{
		if(_firstMainSkill != null)
			return;
		NpcInstance actor = getActor();
		if(actor.getKnownSkill(1263) != null)//curse gloom
			_surrender = SkillTable.getInstance().getInfo(1263, 13);
		else if(actor.getKnownSkill(1071) != null)//surrender to water
			_surrender = SkillTable.getInstance().getInfo(1071, 14);
		else if(actor.getKnownSkill(1074) != null)//surrender to wind
			_surrender = SkillTable.getInstance().getInfo(1074, 14);
		else if(actor.getKnownSkill(1083) != null)//surrender to fire
			_surrender = SkillTable.getInstance().getInfo(1083, 17);
		
		if(actor.getKnownSkill(1339) != null)//Fire vortex
			_firstVortex = SkillTable.getInstance().getInfo(1339, 1);
		else if(actor.getKnownSkill(1343) != null)//Dark vortex
			_firstVortex = SkillTable.getInstance().getInfo(1343, 1);
		else if(actor.getKnownSkill(1342) != null)//Light vortex
			_firstVortex = SkillTable.getInstance().getInfo(1342, 1);
		if(actor.getKnownSkill(1340) != null)//Ice vortex
			_secondVortex = SkillTable.getInstance().getInfo(1340, 1);
		else if(actor.getKnownSkill(1341) != null)//Wind vortex
			_secondVortex = SkillTable.getInstance().getInfo(1341, 1);
		
		if(actor.getKnownSkill(1230) != null)
			_firstMainSkill = SkillTable.getInstance().getInfo(1230, 28);//Prominence
		if(actor.getKnownSkill(1245) != null)
			_firstMainSkill = SkillTable.getInstance().getInfo(1245, 14);//Steal Essence
		if(actor.getKnownSkill(1148) != null && actor.getKnownSkill(1234) != null)
		{
			_firstMainSkill = SkillTable.getInstance().getInfo(1148, 13);//Death Spike
			_secondMainSkill = SkillTable.getInstance().getInfo(1234, 28);//Vampiric Claw
		}
		if(actor.getKnownSkill(1265) != null && actor.getKnownSkill(1235) != null)
		{
			_firstMainSkill = SkillTable.getInstance().getInfo(1265, 14);//Solar Flare
			_secondMainSkill = SkillTable.getInstance().getInfo(1235, 28);//Hydro Blast
		}
		if(actor.getKnownSkill(1239) != null && actor.getKnownSkill(1148) != null)
		{
			_firstMainSkill = SkillTable.getInstance().getInfo(1239, 28);//Hurricane
			_secondMainSkill = SkillTable.getInstance().getInfo(1148, 13);//Death Spike
		}
		
	}
	@Override
	public int getRatePHYS()
	{
		return 0;
	}

	@Override
	public int getRateDOT()
	{
		return 25;
	}

	@Override
	public int getRateDEBUFF()
	{
		return 20;
	}

	@Override
	public int getRateDAM()
	{
		return 100;
	}

	@Override
	public int getRateSTUN()
	{
		return 0;
	}

	@Override
	public int getRateBUFF()
	{
		return 10;
	}

	@Override
	public int getRateHEAL()
	{
		return 20;
	}
}
